﻿using System.ComponentModel;
using System.Xml.Linq;

namespace SharePointUtilitiesForDevelopers
{
    /// <summary>
    /// A domain class that represents a SharePoint list view.
    /// </summary>
    [ReadOnly(true)]
    [DefaultProperty("DisplayName")]
    public class SharePointListView
    {
        /// <summary>
        /// Gets or sets the list name.
        /// </summary>
        /// <value>The list id.</value>
        [Description("The GUID identifier of the list.")]
        public string ListName { get; set; }

        /// <summary>
        /// Gets or sets the definition.
        /// </summary>
        /// <value>The definition.</value>
        [Description("The XML definition of the view.")]
        public XElement Definition { get; set; }

        /// <summary>
        /// Gets or sets the view fields definition.
        /// </summary>
        /// <value>The fields in the view.</value>
        [Description("The XML definition of the view fields.")]
        public XElement ViewFieldsDefinition { get; set; }

        /// <summary>
        /// Gets or sets the view query definition.
        /// </summary>
        /// <value>The view query.</value>
        [Description("The XML definition of the view query.")]
        public XElement QueryDefinition { get; set; }

        /// <summary>
        /// Gets or sets the row limit definition.
        /// </summary>
        /// <value>The row limit definition.</value>
        [Description("The XML definition of the row limit.")]
        public XElement RowLimitDefinition { get; set; }

        /// <summary>
        /// Gets or sets the row limit.
        /// </summary>
        /// <value>The row limit.</value>
        [Description("The maximum rows returned by the view.")]
        public int? RowLimit { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        [Description("The GUID identifier of the view.")]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the display name.
        /// </summary>
        /// <value>The display name.</value>
        [Description("The title of the view.")]
        public string DisplayName { get; set; }

        /// <summary>
        /// Gets or sets the url.
        /// </summary>
        /// <value>The url.</value>
        [Description("The relative url of the view.")]
        public string Url { get; set; }
        
        /// <summary>
        /// Gets or sets a value indicating whether the view is the default for the list.
        /// </summary>
        /// <value><c>true</c> if the default view; otherwise, <c>false</c>.</value>
        [Description("Indicates if the view is the default view for the list.")]
        public bool DefaultView { get; set; }

        /// <summary>
        /// Gets the name of the formatted.
        /// </summary>
        /// <value>The name of the formatted.</value>
        [Description("The formatted name of the view.")]
        [Browsable(false)]
        public string FormattedName
        {
            get
            {
                return ToString();
            }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return string.Format("{0} {1}", DisplayName, DefaultView ? "(Default)" : string.Empty);
        }
    }
}